package com.jin.工厂模式.简单工厂模式.顺从.service;

import com.jin.工厂模式.简单工厂模式.违背.AwardRes;
import com.jin.工厂模式.简单工厂模式.顺从.service.Impl.CardCommodityService;
import com.jin.工厂模式.简单工厂模式.顺从.service.Impl.CouponCommodityService;
import com.jin.工厂模式.简单工厂模式.顺从.service.Impl.GoodsCommodityService;

public class StoreFactory {
    public ICommodity getCommodityService(Integer commodityType){
        if (null==commodityType) return null;
        if (1==commodityType) return new CouponCommodityService();
        if (2==commodityType) return new GoodsCommodityService();
        if (3==commodityType) return new CardCommodityService();
        throw new RuntimeException("不存在奖品的类型");
    }

    //传入的类型必须是ICOMMODITY的子类,传入一个类对象
    public ICommodity getCommodityService(Class<? extends ICommodity> clazz) throws IllegalAccessException, InstantiationException {
        if (null==clazz) return null;
        return clazz.newInstance();

    }

}
